var o, e = require,
    t = module,
    n = exports,
    i = this && this.__extends || (o = function(e, t) {
        return (o = Object.setPrototypeOf || {
                __proto__: []
            }
            instanceof Array && function(e, t) {
                e.__proto__ = t;
            } || function(e, t) {
                for (var o in t) t.hasOwnProperty(o) && (e[o] = t[o]);
            })(e, t);
    }, function(e, t) {
        function n() {
            this.constructor = e;
        }
        o(e, t), e.prototype = null === t ? Object.create(t) : (n.prototype = t.prototype,
            new n());
    }),
    a = this && this.__decorate || function(e, t, o, n) {
        var a, s = arguments.length,
            i = s < 3 ? t : null === n ? n = Object.getOwnPropertyDescriptor(t, o) : n;
        if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) i = Reflect.decorate(e, t, o, n);
        else
            for (var r = e.length - 1; 0 <= r; r--)(a = e[r]) && (i = (s < 3 ? a(i) : 3 < s ? a(t, o, i) : a(t, o)) || i);
        return 3 < s && i && Object.defineProperty(t, o, i), i;
    };

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("Global"),
    s = e("PrefabView"),
    c = e("GameManager"),
    l = e("PersonView"),
    d = e("HeadView"),
    u = e("AudioManager"),
    p = e("GameData"),
    h = e("WebManager"),
    f = e("LoadManager"),
    g = e("UIManager"),
    m = e("AdManager"),
    y = cc._decorator,
    v = y.ccclass,
    w = y.property,
    b = function(t) {
        function e() {
            var e = null !== t && t.apply(this, arguments) || this;
            return e.layout = null, e.headView = null, e.process = null, e.complete = null,
                e.nameLabel = null, e.progress = null, e.progressLabel = null, e.personView = null,
                e.season = null, e.headViews = [], e.loadCount = 0, e.isLoad = !1, e.isProcess = !0,
                e.isComplete = !1, e.isShow = !1, e.isStart = !1, e.openGame = null, e;
        }
        return i(e, t), e.prototype.onDisable = function() {
                m.default.getInstance().hideAllBanner(), t.prototype.onDisable.call(this);
            }, e.prototype.onClickCancal = function() {
                u.default.getInstance().playAudio("按钮2"), h.default.getInstance().sentLog("点击匹配界面取消匹配按键"),
                    g.default.getInstance().hideAllPnl(), g.default.getInstance().showPnl("start");
            }, e.prototype.start = function() {},
            e.prototype.init = function(t, e, o) {

                var n = this;
                n.openGame = o;

                if (void 0 === e && (e = "json/1"), !this.isStart) {
                    this.isStart = !0, 5 < t && (this.headView.node.scale = 1), this.headViews.push(this.headView);
                    for (var a = 0; a < t; a++) {
                        var s = cc.instantiate(this.headView.node);
                        this.headViews.push(s.getComponent(d.default)), s.parent = this.layout;
                    }
                    if (p.GD.playerData && (this.headViews[0].init(p.GD.playerData.icon, p.GD.playerData.nickname, p.GD.personIdx),
                            this.nameLabel.string = this.headViews[0].label.string), 0 == t) this.isLoad = !0
                        /*o && o()*/
                    ;
                    else if (r.G.platform == r.Platform.H4399) {
                        for (this.loadRes(), a = 0; a < t; a++) {
                            var i = c.default.getInstance().model.ais[a];
                            i.nickname = "4399玩家" + (a + 1), this.headViews[a + 1].delayInit(i.icon, i.nickname, .3 * (a + 1), i.personIdx).then(function() {
                                n.loadCount++, n.loadComplete();
                            }).catch(function() {
                                n.loadCount++, n.loadComplete();
                            });
                        }
                        /*o && o()*/
                        ;
                    } else h.default.getInstance().getRobotList({
                        grade: r.G.getRank(p.GD.level).r,
                        weapon: p.GD.topRank,
                        skin: p.GD.personIdx,
                        streak: r.G.wincount,
                        robotNum: t,
                        success: function(e) {
                            0 == e.data.code ? (e.data.data instanceof Array && e.data.data.forEach(function(e, t) {
                                var o = c.default.getInstance().model.ais[t];
                                o.icon = e.icon, o.nickname = e.nickname, isNaN(e.checkTime) || (o.think = e.checkTime / 1e3),
                                    isNaN(e.weapon) || (o.gunIdx = e.weapon), isNaN(e.skin) || (o.personIdx = e.skin),
                                    n.headViews && n.headViews[t + 1] && n.headViews[t + 1].delayInit(e.icon, e.nickname, .3 * (t + 1), o.personIdx).then(function() {
                                        n.loadCount++, n.loadComplete();
                                    }).catch(function() {
                                        n.loadCount++, n.loadComplete();
                                    });
                            }) /*, o && o()*/ ) : h.default.getInstance().getSomeRobots({
                                limit: t,
                                success: function(e) {
                                    cc.log("getSomeRobots", e), e.data.data instanceof Array && e.data.data.forEach(function(e, t) {
                                        var o = c.default.getInstance().model.ais[t];
                                        o.icon = e.icon, o.nickname = e.nickname, n.headViews && n.headViews[t + 1] && n.headViews[t + 1].delayInit(e.icon, e.nickname, .3 * (t + 1), o.personIdx).then(function() {
                                            n.loadCount++, n.loadComplete();
                                        }).catch(function() {
                                            n.loadCount++, n.loadComplete();
                                        });
                                    }) /*, o && o()*/ ;
                                },
                                fail: function(e) {
                                    console.error(e);
                                }
                            });
                        },
                        fail: function(e) {
                            console.error(e);
                        }
                    }), this.scheduleOnce(function() {
                        n.isLoad = !0;
                    }, .5 * t);
                    f.default.getInstance().loadRes({
                        url: e,
                        type: cc.JsonAsset
                    }).then(function() {
                        n.isComplete = !0;
                    });
                }
            }, e.prototype.loadRes = function() {
                return Promise.all([new Promise(function(t) {
                    cc.resources.loadDir("texture/bullet", cc.SpriteFrame, function(e) {
                        e && console.error(e), t();
                    });
                }), new Promise(function(t) {
                    cc.resources.loadDir("skeleton", sp.SkeletonData, function(e) {
                        e && console.error(e), t();
                    });
                }), new Promise(function(t) {
                    cc.resources.loadDir("skin", sp.SkeletonData, function(e) {
                        e && console.error(e), t();
                    });
                })]);
            }, e.prototype.loadComplete = function() {
                this.loadCount >= c.default.getInstance().aicount && (this.isLoad = !0);
            }, e.prototype.showGame = function() {
                this.openGame && this.openGame();
                this.unscheduleAllCallbacks(), this.hidePnl(), c.default.getInstance().doStart();
            }, e.prototype.showSeason = function() {
                this.progress.node.parent.y = -260, this.personView.node.active = !1, this.season.active = !0;
            }, e.prototype.update = function(e) {
                var t = this;
                this.isProcess && this.isLoad && (this.isLoad = !1, this.scheduleOnce(function() {
                    var e;
                    t.isProcess = !1, t.process.active = !1, t.complete.active = !0, t.personView.init(),
                        p.GD.hasSkin(r.G.seasonPersonIdx) || (e = Math.ceil(r.G.seasonNextTime / r.G.ONE_DAY_TIME)) < 4 && 0 < e && t.showSeason();
                }, 1)), this.isProcess || this.isShow || (this.progress.fillRange < .99 ? (this.progress.fillRange += e / 1.2,
                    this.progressLabel.string = "加载" + Math.floor(100 * this.progress.fillRange) + "%") : this.isComplete && (this.isShow = !0,
                    this.progress.fillRange = 1, this.progressLabel.string = "加载100%", this.showGame()));
            }, a([w(cc.Node)], e.prototype, "layout", void 0), a([w(d.default)], e.prototype, "headView", void 0),
            a([w(cc.Node)], e.prototype, "process", void 0), a([w(cc.Node)], e.prototype, "complete", void 0),
            a([w(cc.Label)], e.prototype, "nameLabel", void 0), a([w(cc.Sprite)], e.prototype, "progress", void 0),
            a([w(cc.Label)], e.prototype, "progressLabel", void 0), a([w(l.default)], e.prototype, "personView", void 0),
            a([w(cc.Node)], e.prototype, "season", void 0), a([v], e);
    }(s.default);

n.default = b;